###Diplomatic Statements and the Strategic Use of Terrorism in Civil Wars###
###Levy, Dudley, Chen, Siegel###
###Journal of Conflict Resolution###
###R Script 3: Figure A1-A3, A6-A8 and Figure A10 in the Online Appendix###

rm(list = ls())

#setwd("Replication")

library(dplyr)
library(lme4)
library(texreg)
library(ggplot2)
library(coefplot)
library(stargazer)
library(merTools)
library(ggeffects)
library(ggpubr)
library(gridGraphics)
library(patchwork)
library(egg)
library(sjPlot)
library(ggpubr)
library(estimatr)
library(lubridate)
library(xtable)
library(Hmisc)
library(pastecs)
source("Code/functions.R")
load("Data/df.RData")

####Figure A1####

l2.prop <- lm(CivAttackProp2 ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                prev_res_reb_lag3 + prev_res_gov_lag3 +
                any_reb_int_lag2 + any_gov_int_lag2 +
                physint + lngdppc + lntpop + rebstrength2 + CivAttackProp2_lag + 
                coldwar +rebels_count + duration,
              data = df)

l2.propXP <- lm(CivAttackProp2 ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 + 
                  reb_X_d_lag2 + gov_X_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp2_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l2.propWP <- lm(CivAttackProp2 ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 +
                  reb_W_d_lag2 + gov_W_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp2_lag +
                  coldwar +rebels_count + duration,
                data = df)

l2.propEP <- lm(CivAttackProp2 ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 +
                  reb_E_d_lag2 + gov_E_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp2_lag +
                  coldwar +rebels_count + duration,
                data = df)

fig_coef_A <- LM_coef(modResults = list(l2.prop, l2.propXP, l2.propWP, l2.propEP), data = df, 
                      vars = c("(Intercept)", "duration", "rebels_count","coldwar",
                               "rebstrength2","lntpop", "lngdppc", "physint","gov_E_d_lag2","reb_E_d_lag2",
                               "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2" ,
                               "any_gov_int_lag2","any_reb_int_lag2",
                               "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                               "pro_reb_res_lag2",
                               "CivAttackProp2_lag")) +
  scale_x_discrete(labels=c("Intercept", "Conflict Duration","Count of Rebel Groups",
                            "Cold War", "Rebel Strength", "Logged Population",
                            "Logged GDP per capita", "Physical Integrity Rights", 
                            "Pro Gov Intervention, Economic", "Pro Reb Intervention, Economic", 
                            "Pro Gov Intervention, Weapons", "Pro Reb Intervention, Weapons",
                            "Pro Gov Intervention, Troops", "Pro Reb Intervention, Troops", 
                            "Any Pro-Government Support","Any Pro-Rebel Support",
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution", 
                            "Lagged DV (Prop Attacks Against Civilians)")) +
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic"))+
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) + 
  labs(title = "",
       subtitle = "DV: Proportion of Attacks against Civilians",
       caption = "Note: Only Military and Police targets (linear models)", 
       x = "", y = "")

ggsave("Figures/Fig_A1.jpeg", 
       plot = fig_coef_A, dpi = 600, width = 9, height = 6)


####Figure A2####

mod3.prop <- lm(CivFatalityProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 +
                  any_reb_int_lag2 + any_gov_int_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivFatalityProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

mod3.propXP <- lm(CivFatalityProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                    prev_res_reb_lag3 + prev_res_gov_lag3 + 
                    reb_X_d_lag2 + gov_X_d_lag2 +
                    physint + lngdppc + lntpop + rebstrength2 + CivFatalityProp_lag + 
                    coldwar +rebels_count + duration,
                  data = df)

mod3.propWP <- lm(CivFatalityProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                    prev_res_reb_lag3 + prev_res_gov_lag3 +
                    reb_W_d_lag2 + gov_W_d_lag2 +
                    physint + lngdppc + lntpop + rebstrength2 + CivFatalityProp_lag +
                    coldwar +rebels_count + duration,
                  data = df)

mod3.propEP <- lm(CivFatalityProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                    prev_res_reb_lag3 + prev_res_gov_lag3 +
                    reb_E_d_lag2 + gov_E_d_lag2 +
                    physint + lngdppc + lntpop + rebstrength2 + CivFatalityProp_lag +
                    coldwar +rebels_count + duration,
                  data = df)


fig_Prop <- LM_coef(modResults = list(mod3.prop, mod3.propXP, mod3.propWP, mod3.propEP), data = df, 
                    vars = c("(Intercept)", "duration", "rebels_count","coldwar",
                             "rebstrength2","lntpop", "lngdppc", "physint","gov_E_d_lag2","reb_E_d_lag2",
                             "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2" ,
                             "any_gov_int_lag2","any_reb_int_lag2",
                             "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                             "pro_reb_res_lag2",
                             "CivFatalityProp_lag")) + 
  scale_x_discrete(labels=c("Intercept", "Conflict Duration","Count of Rebel Groups",
                            "Cold War", "Rebel Strength", "Logged Population",
                            "Logged GDP per capita", "Physical Integrity Rights", 
                            "Pro Gov Intervention, Economic", "Pro Reb Intervention, Economic", 
                            "Pro Gov Intervention, Weapons", "Pro Reb Intervention, Weapons",
                            "Pro Gov Intervention, Troops", "Pro Reb Intervention, Troops", 
                            "Any Pro-Government Support","Any Pro-Rebel Support",
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution", 
                            "Lagged DV (Prop Attacks Against Civilians)")) +
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  labs(title = "",
       subtitle = "DV: Proportion of Civilian Fatalities",
       caption = "Note: linear models", 
       x = "", y = "") 

ggsave("Figures/Fig_A2.jpeg", 
       plot = fig_Prop, dpi = 600, width = 9, height = 6)


####Figure A3####

mod1.civ0 <- lm(NumCivAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 + 
                  any_reb_int_lag2 + any_gov_int_lag2 +
                  physint + lngdppc + lntpop + rebstrength2  + 
                  coldwar +rebels_count + duration + NumCivAttacks_lag,
                data = df)

mod1.civ <- lm(NumCivAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_X_d_lag2 + gov_X_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumCivAttacks_lag,
               data = df)

mod1.mil0 <- lm(NumMilAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 + 
                  any_reb_int_lag2 + any_gov_int_lag2 +
                  physint + lngdppc + lntpop + rebstrength2  + 
                  coldwar +rebels_count + duration + NumMilAttacks_lag,
                data = df)

mod1.mil <- lm(NumMilAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_X_d_lag2 + gov_X_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumMilAttacks_lag,
               data = df)

mod2.civ <- lm(NumCivAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_W_d_lag2 + gov_W_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumCivAttacks_lag,
               data = df)

mod2.mil <- lm(NumMilAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_W_d_lag2 + gov_W_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumMilAttacks_lag,
               data = df)

mod3.civ <- lm(NumCivAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_E_d_lag2 + gov_E_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumCivAttacks_lag,
               data = df)

mod3.mil <- lm(NumMilAttacks ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                 prev_res_reb_lag3 + prev_res_gov_lag3 + 
                 reb_E_d_lag2 + gov_E_d_lag2 +
                 physint + lngdppc + lntpop + rebstrength2  + 
                 coldwar +rebels_count + duration + NumMilAttacks_lag,
               data = df)

## Figure A3A
count_mil <- LM_coef(modResults = list(mod1.mil0, mod1.mil, mod2.mil,mod3.mil), data = df, 
                     vars = c("(Intercept)","coldwar","rebels_count", "duration","rebstrength2",
                              "lntpop", "lngdppc", "physint","gov_E_d_lag2","reb_E_d_lag2",
                              "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2" ,
                              "any_gov_int_lag2","any_reb_int_lag2",
                              "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                              "pro_reb_res_lag2","NumMilAttacks_lag"
                     )) +
  scale_x_discrete(labels=c("Intercept", "Cold War","Count of Rebel Groups", "Conflict Duration",
                            "Rebel Strength", "Logged Population",
                            "Logged GDP per capita", "Physical Integrity Rights", 
                            "Pro Gov Intervention, Economic", "Pro Reb Intervention, Economic", 
                            "Pro Gov Intervention, Weapons", "Pro Reb Intervention, Weapons",
                            "Pro Gov Intervention, Troops", "Pro Reb Intervention, Troops", 
                            "Any Pro-Government Support","Any Pro-Rebel Support",
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution", 
                            "Lagged DV (Count of Military Targets)")) + 
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic"))+
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  labs(title = "Military Targets",
       subtitle = "DV: Count of Military Targets",
       caption = "Note: Linear Models with lagged DV") +
  theme(legend.position = "bottom")+ labs(y = "")
ggsave("Figures/Fig_A3a.jpeg", plot = count_mil, dpi = 600, width = 8, height = 6)

## Figure A3B
count_civ <- LM_coef(modResults = list(mod1.civ0, mod1.civ, mod2.civ, mod3.civ), data = df, 
                     vars = c("(Intercept)","coldwar","rebels_count", "duration","rebstrength2",
                              "lntpop", "lngdppc", "physint","gov_E_d_lag2","reb_E_d_lag2",
                              "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2" ,
                              "any_gov_int_lag2","any_reb_int_lag2",
                              "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                              "pro_reb_res_lag2", "NumCivAttacks_lag")) +
  scale_x_discrete(labels=c("Intercept", "Cold War","Count of Rebel Groups", "Conflict Duration",
                            "Rebel Strength", "Logged Population",
                            "Logged GDP per capita", "Physical Integrity Rights", 
                            "Pro Gov Intervention, Economic", "Pro Reb Intervention, Economic", 
                            "Pro Gov Intervention, Weapons", "Pro Reb Intervention, Weapons",
                            "Pro Gov Intervention, Troops", "Pro Reb Intervention, Troops", 
                            "Any Pro-Government Support","Any Pro-Rebel Support",
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution", 
                            "Lagged DV (Count of Civilian Targets)")) + 
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  labs(title = "Civilian Targets",
       subtitle = "DV: Count of Civilian Targets",
       caption = "Note: Linear Models with lagged DV") + 
  theme(legend.position = "bottom")+ labs(y = "")
ggsave("Figures/Fig_A3b.jpeg", plot = count_civ, dpi = 600, width = 8, height = 6)


####Figure A6####

# Figure A6A
mod.othint.propLP2 <- lm(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                           prev_res_reb_lag3 + prev_res_gov_lag3 + 
                           reb_L_d_lag2 + gov_L_d_lag2 +
                           physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                           coldwar +rebels_count + duration ,
                           data = df)

mod.othint.propMP2 <- lm(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                           prev_res_reb_lag3 + prev_res_gov_lag3 + 
                           reb_M_d_lag2 + gov_M_d_lag2 +
                           physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                           coldwar +rebels_count + duration,
                           data = df)

mod.othint.propTP2 <- lm(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                           prev_res_reb_lag3 + prev_res_gov_lag3 + 
                           reb_T_d_lag2 + gov_T_d_lag2 +
                           physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                           coldwar +rebels_count + duration,
                           data = df)

mod.othint.propIP2 <- lm(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                           prev_res_reb_lag3 + prev_res_gov_lag3 + 
                           reb_I_d_lag2 + gov_I_d_lag2 +
                           physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                           coldwar +rebels_count + duration,
                           data = df)

fig_lm_other <- LM_coef(modResults = list(mod.othint.propLP2, mod.othint.propMP2, mod.othint.propTP2, mod.othint.propIP2), data = df, 
                        vars = c("(Intercept)","coldwar","rebels_count", "duration", "rebstrength2",
                                 "lntpop", "lngdppc", "physint","reb_L_d_lag2", "gov_L_d_lag2",
                                 "reb_M_d_lag2","gov_M_d_lag2" , "reb_T_d_lag2", "gov_T_d_lag2",
                                 "reb_I_d_lag2", "gov_I_d_lag2",
                                 "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                                 "pro_reb_res_lag2", "CivAttackProp_lag")) + 
  scale_x_discrete(labels=c("Intercept", "Cold War", "Count of Rebel Groups","Conflict Duration",
                            "Rebel Strength","Logged Population","Logged GDP per capita",
                            "Physical Integrity Rights",  "Pro Reb Intervention, Military Access", "Pro Gov Intervention, Military Access", 
                            "Pro Reb Intervention, Materiel/Logistics","Pro Gov Intervention, Materiel/Logistics",  "Pro Reb Intervention, Training/Expertise", 
                            "Pro Gov Intervention, Training/Expertise",  "Pro Reb Intervention, Intelligence", "Pro Gov Intervention, Intelligence", 
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution", "Lagged DV (Prop Attacks Against Civilians)")) +
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) + 
  labs(title = "",
       subtitle = "DV: Proportion of Attacks against Civilians",
       caption = "Note: other forms of intervention (linear models)", 
       x = "", y = "") 

ggsave("Figures/Fig_A6a.jpeg", 
       plot = fig_lm_other, dpi = 600, width = 9, height = 6)

# Figure A6B
mod.othint.propLP <- lmer(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                            prev_res_reb_lag3 + prev_res_gov_lag3 + 
                            reb_L_d_lag2 + gov_L_d_lag2 +
                            physint + lngdppc + lntpop + rebstrength2 +
                            coldwar +rebels_count + duration +
                            (1 | country) + (1 | year),
                          data = df)

mod.othint.propMP <- lmer(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                            prev_res_reb_lag3 + prev_res_gov_lag3 + 
                            reb_M_d_lag2 + gov_M_d_lag2 +
                            physint + lngdppc + lntpop + rebstrength2 + 
                            coldwar +rebels_count + duration +
                            (1 | country) + (1 | year),
                          data = df)

mod.othint.propTP <- lmer(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                            prev_res_reb_lag3 + prev_res_gov_lag3 + 
                            reb_T_d_lag2 + gov_T_d_lag2 +
                            physint + lngdppc + lntpop + rebstrength2 + 
                            coldwar +rebels_count + duration +
                            (1 | country) + (1 | year),
                          data = df)

mod.othint.propIP <- lmer(CivAttackProp ~  pro_reb_res_lag2 + pro_gov_res_lag2 + 
                            prev_res_reb_lag3 + prev_res_gov_lag3 + 
                            reb_I_d_lag2 + gov_I_d_lag2 +
                            physint + lngdppc + lntpop + rebstrength2 + 
                            coldwar +rebels_count + duration +
                            (1 | country) + (1 | year),
                          data = df)

fig_mlm_other <- MLM_coef(modResults = list(mod.othint.propLP, mod.othint.propMP, mod.othint.propTP, mod.othint.propIP), data = df,
                          vars = c("(Intercept)","coldwar","rebels_count", "duration", "rebstrength2",
                                   "lntpop", "lngdppc", "physint","reb_L_d_lag2", "gov_L_d_lag2",
                                   "reb_M_d_lag2","gov_M_d_lag2" , "reb_T_d_lag2", "gov_T_d_lag2",
                                   "reb_I_d_lag2", "gov_I_d_lag2",
                                   "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                                   "pro_reb_res_lag2")) + 
  scale_x_discrete(labels=c("Intercept", "Cold War", "Count of Rebel Groups","Conflict Duration",
                            "Rebel Strength","Logged Population","Logged GDP per capita",
                            "Physical Integrity Rights",  "Pro Reb Intervention, Military Access", "Pro Gov Intervention, Military Access", 
                            "Pro Reb Intervention, Materiel/Logistics","Pro Gov Intervention, Materiel/Logistics",  "Pro Reb Intervention, Training/Expertise", 
                            "Pro Gov Intervention, Training/Expertise",  "Pro Reb Intervention, Intelligence", "Pro Gov Intervention, Intelligence", 
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution")) +
  scale_shape_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c("Any",
                                "Troops", 
                                "Weapons",
                                "Economic")) + 
  labs(title = "",
       subtitle = "DV: Proportion of Attacks against Civilians",
       caption = "Note: other forms of intervention (mixed-effects models)", 
       x = "", y = "") 

ggsave("Figures/Fig_A6b.jpeg", 
       plot = fig_mlm_other, dpi = 600, width = 9, height = 6)

####Figure A7####
# take out Israel (max 171) -- next Afghanistan (68), South Africa (65) -- next is Sudan at 24

df2vars <- c("cnty_month", "prev_res_reb_lag2")
df2 <- df[df2vars]

df3 <- df[which(df$country!="Israel" | df$country!="Afghanistan" | df$country!="South Africa"), ]


mod_outliers.propXP <- lmer(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                              prev_res_reb_lag3 + prev_res_gov_lag3 + 
                              reb_X_d_lag2 + gov_X_d_lag2 +
                              physint + lngdppc + lntpop + rebstrength2 +
                              coldwar +rebels_count + duration+
                              (1 | country) + (1 | year),
                            data = df3)

mod_outliers.propWP <- lmer(CivAttackProp ~pro_reb_res_lag2 + pro_gov_res_lag2 + 
                              prev_res_reb_lag3 + prev_res_gov_lag3 +
                              reb_W_d_lag2 + gov_W_d_lag2 +
                              physint + lngdppc + lntpop + rebstrength2 + 
                              coldwar +rebels_count + duration+
                              (1 | country) + (1 | year),
                            data = df3)

mod_outliers.propEP <- lmer(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                              prev_res_reb_lag3 + prev_res_gov_lag3  +
                              reb_E_d_lag2 + gov_E_d_lag2 +
                              physint + lngdppc + lntpop + rebstrength2 +
                              coldwar +rebels_count + duration+
                              (1 | country) + (1 | year),
                            data = df3)

fig_coef_outl <- MLM_coef(modResults = list(mod_outliers.propXP,mod_outliers.propWP,mod_outliers.propEP), data = df,
                          vars = c("(Intercept)","coldwar","rebels_count", "duration","rebstrength2",
                                   "lntpop", "lngdppc", "physint","gov_E_d_lag2","reb_E_d_lag2",
                                   "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2" ,
                                   "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                                   "pro_reb_res_lag2")) + 
  scale_x_discrete(labels=c("Intercept", "Cold War", "Count of Rebel Groups","Conflict Duration",
                            "Rebel Strength","Logged Population","Logged GDP per capita",
                            "Physical Integrity Rights", "Pro Gov Intervention, Economic", "Pro Reb Intervention, Economic", 
                            "Pro Gov Intervention, Weapons", "Pro Reb Intervention, Weapons",
                            "Pro Gov Intervention, Troops", "Pro Reb Intervention, Troops", 
                            "Any Pro-Government Support","Any Pro-Rebel Support",
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution")) +
  scale_shape_discrete(labels=c(
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c(
                                "Troops", 
                                "Weapons",
                                "Economic")) + 
  labs(title = "",
       subtitle = "DV: Proportion of Attacks against Civilians",
       caption = "Note: Excluding Israel, Afghanistan and South Africa (mixed-effects models)", 
       x = "", y = "") 
ggsave("Figures/Fig_A7.jpeg", 
       plot = fig_coef_outl, dpi = 600, width = 9, height = 6)

####Figure A8####

mod.prevint.propXP <- lmer(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                             prev_res_reb_lag3 + prev_res_gov_lag3 + 
                             prev_reb_X_d_lag3 + prev_gov_X_d_lag3 +
                             physint + lngdppc + lntpop + rebstrength2 +
                             coldwar +rebels_count + duration+
                             (1 | country) + (1 | year),
                           data = df)

mod.prevint.propWP <- lmer(CivAttackProp ~pro_reb_res_lag2 + pro_gov_res_lag2 + 
                             prev_res_reb_lag3 + prev_res_gov_lag3 +
                             prev_reb_W_d_lag3 + prev_gov_W_d_lag3 +
                             physint + lngdppc + lntpop + rebstrength2 + 
                             coldwar +rebels_count + duration+
                             (1 | country) + (1 | year),
                           data = df)

mod.prevint.propEP <- lmer(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                             prev_res_reb_lag3 + prev_res_gov_lag3 +
                             prev_reb_E_d_lag3 + prev_gov_E_d_lag3 +
                             physint + lngdppc + lntpop + rebstrength2 + 
                             coldwar +rebels_count + duration+
                             (1 | country) + (1 | year),
                           data = df)


fig_mlm_prevint <- MLM_coef(modResults = list(mod.prevint.propXP, mod.prevint.propWP, mod.prevint.propEP), data = df,
                            vars = c("(Intercept)","coldwar","rebels_count", "duration", "rebstrength2",
                                     "lntpop", "lngdppc", "physint",
                                     "prev_reb_E_d_lag3", "prev_gov_E_d_lag3",
                                     "prev_reb_W_d_lag3","prev_gov_W_d_lag3",
                                     "prev_reb_X_d_lag3", "prev_gov_X_d_lag3", 
                                     "prev_res_gov_lag3","prev_res_reb_lag3","pro_gov_res_lag2",
                                     "pro_reb_res_lag2")) + 
  scale_x_discrete(labels=c("Intercept", "Cold War", "Count of Rebel Groups","Conflict Duration",
                            "Rebel Strength","Logged Population","Logged GDP per capita",
                            "Physical Integrity Rights", "Previous Pro Reb Intervention, Economic", 
                            "Previous Pro Gov Intervention, Economic", "Previous Pro Reb Intervention, Weapons","Previous Pro Gov Intervention, Weapons", 
                            "Previous Pro Reb Intervention, Troops", "Previous Pro Gov Intervention, Troops", 
                            "Previous Pro Gov Res, Count", "Previous Pro Reb Res, Count", 
                            "Pro-Government Resolution","Pro-Rebel Resolution")) +
  scale_shape_discrete(labels=c(
                                "Troops", 
                                "Weapons",
                                "Economic")) +
  scale_color_discrete(labels=c(
                                "Troops", 
                                "Weapons",
                                "Economic")) + 
  labs(title = "",
       subtitle = "DV: Proportion of Attacks against Civilians",
       caption = "Note: Previous months with interventions (mixed-effects models)", 
       x = "", y = "") 

ggsave("Figures/Fig_A8.jpeg", 
       plot =fig_mlm_prevint , dpi = 600, width = 9, height = 6)


####Figure A10####

df <- df %>%
  dplyr::group_by(conflict_id) %>%
  dplyr::arrange(conflict_id,month) %>% 
  dplyr::mutate(reb_X_d_lag3 = lag(reb_X_d, n= 3 ),
                gov_X_d_lag3 = lag(gov_X_d, n=3 ),
                reb_E_d_lag3 = lag(reb_E_d, n=3 ),
                gov_E_d_lag3 = lag(gov_E_d, n=3 ),
                reb_W_d_lag3 = lag(reb_W_d, n=3 ),
                gov_W_d_lag3 = lag(gov_W_d, n=3 ),
                
                gov_X_d_lag4 = lag(gov_X_d, n=4 ),
                reb_X_d_lag4 = lag(reb_X_d, n=4 ),
                reb_E_d_lag4 = lag(reb_E_d, n=4 ),
                gov_E_d_lag4 = lag(gov_E_d, n=4 ),
                reb_W_d_lag4 = lag(reb_W_d, n=4 ),
                gov_W_d_lag4 = lag(gov_W_d, n=4 ),
                
                reb_X_d_lag5 = lag(reb_X_d, n=5 ),
                gov_X_d_lag5 = lag(gov_X_d, n=5 ),
                reb_E_d_lag5 = lag(reb_E_d, n=5 ),
                gov_E_d_lag5 = lag(gov_E_d, n=5 ),
                reb_W_d_lag5 = lag(reb_W_d, n=5 ),
                gov_W_d_lag5 = lag(gov_W_d, n=5 ),
                
                reb_X_d_lag6 = lag(reb_X_d, n=6 ),
                gov_X_d_lag6 = lag(gov_X_d, n=6 ),
                reb_E_d_lag6 = lag(reb_E_d, n=6 ),
                gov_E_d_lag6 = lag(gov_E_d, n=6 ),
                reb_W_d_lag6 = lag(reb_W_d, n=6 ),
                gov_W_d_lag6 = lag(gov_W_d, n=6 ),
                
                gov_X_d_lag7 = lag(gov_X_d, n=7 ),
                reb_X_d_lag7 = lag(reb_X_d, n=7 ),
                reb_E_d_lag7 = lag(reb_E_d, n=7 ),
                gov_E_d_lag7 = lag(gov_E_d, n=7 ),
                reb_W_d_lag7 = lag(reb_W_d, n=7 ),
                gov_W_d_lag7 = lag(gov_W_d, n=7 ))




#2-lag
l2.propXP <- lm(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 + 
                  reb_X_d_lag2 + gov_X_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l2.propWP <- lm(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 +
                  reb_W_d_lag2 + gov_W_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l2.propEP <- lm(CivAttackProp ~ pro_reb_res_lag2 + pro_gov_res_lag2 + 
                  prev_res_reb_lag3 + prev_res_gov_lag3 +
                  reb_E_d_lag2 + gov_E_d_lag2 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)
summary(l2.propEP)  

## 3-lag
l3.propXP <- lm(CivAttackProp ~ pro_reb_res_lag3 + pro_gov_res_lag3 + 
                  prev_res_reb_lag4 + prev_res_gov_lag4 + 
                  reb_X_d_lag3 + gov_X_d_lag3 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l3.propWP <- lm(CivAttackProp ~ pro_reb_res_lag3 + pro_gov_res_lag3 + 
                  prev_res_reb_lag4 + prev_res_gov_lag4 +
                  reb_W_d_lag3 + gov_W_d_lag3 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l3.propEP <- lm(CivAttackProp ~ pro_reb_res_lag3 + pro_gov_res_lag3 + 
                  prev_res_reb_lag4 + prev_res_gov_lag4 +
                  reb_E_d_lag3 + gov_E_d_lag3 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

## 4-lag
l4.propXP <- lm(CivAttackProp ~ pro_reb_res_lag4 + pro_gov_res_lag4 + 
                  prev_res_reb_lag5 + prev_res_gov_lag5 + 
                  reb_X_d_lag4 + gov_X_d_lag4 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l4.propWP <- lm(CivAttackProp ~ pro_reb_res_lag4 + pro_gov_res_lag4 + 
                  prev_res_reb_lag4 + prev_res_gov_lag4 +
                  reb_W_d_lag4 + gov_W_d_lag4 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l4.propEP <- lm(CivAttackProp ~ pro_reb_res_lag4 + pro_gov_res_lag4 + 
                  prev_res_reb_lag5 + prev_res_gov_lag5 +
                  reb_E_d_lag4 + gov_E_d_lag4 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

# 5-lag
l5.propXP <- lm(CivAttackProp ~ pro_reb_res_lag5 + pro_gov_res_lag5 + 
                  prev_res_reb_lag6 + prev_res_gov_lag6 + 
                  reb_X_d_lag5 + gov_X_d_lag5 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l5.propWP <- lm(CivAttackProp ~ pro_reb_res_lag5 + pro_gov_res_lag5 + 
                  prev_res_reb_lag6 + prev_res_gov_lag6 +
                  reb_W_d_lag5 + gov_W_d_lag5 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l5.propEP <- lm(CivAttackProp ~ pro_reb_res_lag5 + pro_gov_res_lag5 + 
                  prev_res_reb_lag6 + prev_res_gov_lag6 +
                  reb_E_d_lag5 + gov_E_d_lag5 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

# 6-lag
l6.propXP <- lm(CivAttackProp ~ pro_reb_res_lag6 + pro_gov_res_lag6 + 
                  prev_res_reb_lag7 + prev_res_gov_lag7 + 
                  reb_X_d_lag6 + gov_X_d_lag6 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l6.propWP <- lm(CivAttackProp ~ pro_reb_res_lag6 + pro_gov_res_lag6 + 
                  prev_res_reb_lag7 + prev_res_gov_lag7 +
                  reb_W_d_lag6 + gov_W_d_lag6 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l6.propEP <- lm(CivAttackProp ~ pro_reb_res_lag6 + pro_gov_res_lag6 + 
                  prev_res_reb_lag7 + prev_res_gov_lag7 +
                  reb_E_d_lag6 + gov_E_d_lag6 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

# 7-lag
l7.propXP <- lm(CivAttackProp ~ pro_reb_res_lag7 + pro_gov_res_lag7 + 
                  prev_res_reb_lag8 + prev_res_gov_lag8 + 
                  reb_X_d_lag7 + gov_X_d_lag7 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag + 
                  coldwar +rebels_count + duration,
                data = df)

l7.propWP <- lm(CivAttackProp ~ pro_reb_res_lag7 + pro_gov_res_lag7 + 
                  prev_res_reb_lag8 + prev_res_gov_lag8 +
                  reb_W_d_lag7 + gov_W_d_lag7 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

l7.propEP <- lm(CivAttackProp ~ pro_reb_res_lag7 + pro_gov_res_lag7 + 
                  prev_res_reb_lag8 + prev_res_gov_lag8 +
                  reb_E_d_lag7 + gov_E_d_lag7 +
                  physint + lngdppc + lntpop + rebstrength2 + CivAttackProp_lag +
                  coldwar +rebels_count + duration,
                data = df)

lag2 <- LM_coef(modResults = list(l2.propXP, l2.propWP, l2.propEP), data = df, 
                vars = c("gov_E_d_lag2","reb_E_d_lag2",
                         "gov_W_d_lag2","reb_W_d_lag2","gov_X_d_lag2","reb_X_d_lag2",
                         "pro_gov_res_lag2",
                         "pro_reb_res_lag2"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops",
                            "Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops", 
                                "Weapons",
                                "Economic"))+
  scale_color_discrete(labels=c("Troops", 
                                "Weapons",
                                "Economic"))+
  ggtitle("2-month lags")+theme(legend.position = "none") + labs(y = "")

lag3<- LM_coef(modResults = list(l3.propXP, l3.propWP, l3.propEP), data = df, 
               vars = c("gov_E_d_lag3","reb_E_d_lag3",
                        "gov_W_d_lag3","reb_W_d_lag3","gov_X_d_lag3","reb_X_d_lag3","pro_gov_res_lag3",
                        "pro_reb_res_lag3"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops",
                            "Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  scale_color_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  ggtitle("3-month lags")+theme(legend.position = "none")+ labs(y = "")

lag4<- LM_coef(modResults = list(l4.propXP, l4.propWP, l4.propEP), data = df, 
               vars = c("gov_E_d_lag4","reb_E_d_lag4",
                        "gov_W_d_lag4","reb_W_d_lag4","gov_X_d_lag4","reb_X_d_lag4","pro_gov_res_lag4",
                        "pro_reb_res_lag4"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops","Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  scale_color_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  ggtitle("4-month lags")

lag5<- LM_coef(modResults = list(l5.propXP, l5.propWP, l5.propEP), data = df, 
               vars = c("gov_E_d_lag5","reb_E_d_lag5",
                        "gov_W_d_lag5","reb_W_d_lag5","gov_X_d_lag5","reb_X_d_lag5","pro_gov_res_lag5",
                        "pro_reb_res_lag5"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops","Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  scale_color_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  ggtitle("5-month lags")+theme(legend.position = "none")+ labs(y = "")

lag6<- LM_coef(modResults = list(l6.propXP, l6.propWP, l6.propEP), data = df, 
               vars = c("gov_E_d_lag6","reb_E_d_lag6",
                        "gov_W_d_lag6","reb_W_d_lag6","gov_X_d_lag6","reb_X_d_lag6","pro_gov_res_lag6",
                        "pro_reb_res_lag6"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops","Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  scale_color_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  ggtitle("6-month lags")+theme(legend.position = "none")+ labs(y = "")

lag7<- LM_coef(modResults = list(l7.propXP, l7.propWP, l7.propEP), data = df, 
               vars = c("gov_E_d_lag7","reb_E_d_lag7",
                        "gov_W_d_lag7","reb_W_d_lag7","gov_X_d_lag7","reb_X_d_lag7","pro_gov_res_lag7",
                        "pro_reb_res_lag7"))+ 
  scale_x_discrete(labels=c("Pro Gov , Economic", "Pro Reb , Economic", 
                            "Pro Gov , Weapons", "Pro Reb , Weapons",
                            "Pro Gov , Troops", "Pro Reb , Troops","Pro-Government Resolution","Pro-Rebel Resolution"))+ 
  scale_shape_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  scale_color_discrete(labels=c("Troops ", 
                                "Weapons ",
                                "Economic "))+
  ggtitle("7-month lags")+theme(legend.position = "none")

lags_coplot <- ggarrange(lag2, lag3, lag4, lag5, lag6, lag7,
                         ncol = 2, nrow = 3, byrow = FALSE)
ggsave("Figures/Fig_A10.jpeg", 
       plot = lags_coplot, dpi = 600, width = 12, height = 8 )

